/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mobiwebinc.compconn.factory;

import com.mobiwebinc.compconn.systray.SysTray;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author suraj
 */
public class SysTrayFactory {

    private static SysTrayFactory sysTrayFactory;
    private static SysTray sysTray;

    public static SysTrayFactory getInstance() {
        if (sysTrayFactory == null) {
            sysTrayFactory = new SysTrayFactory();
        }
        return sysTrayFactory;
    }

    public SysTray getSysTray() {
        try {
            if (sysTray == null) {
                if (isSysTrayPresent()) {
                    sysTray = ((SysTray) Class.forName("com.mobiwebinc.compconn.systray.WindowSysTray").newInstance());
                } else if (isMacDock()) {
                    sysTray = ((SysTray) Class.forName("com.mobiwebinc.compconn.systray.MacTray").newInstance());
                } else {
                    sysTray = ((SysTray) Class.forName("com.mobiwebinc.compconn.systray.DummyTray").newInstance());
                }
            }
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(SysTrayFactory.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            Logger.getLogger(SysTrayFactory.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(SysTrayFactory.class.getName()).log(Level.SEVERE, null, ex);
        }
        return sysTray;
    }

    private boolean isSysTrayPresent() {
        try {
            Class.forName("java.awt.SystemTray").getDeclaredMethods();
        } catch (Exception ex) {
            return false;
        }
        return true;
    }

    private boolean isMacDock() {
        try {
            Class.forName("com.apple.eawt.Application");
        } catch (ClassNotFoundException ex) {
            return false;
        }
        return true;
    }
}
